package photostock.view;

import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class Widget extends Element {

	public static final long serialVersionUID = 20090501L;
	
	public Widget(String s) {
		super(s);
	}

	public Widget(String s, String cl, String id) {
		super(s);
		setAttribute("class", cl);
		setAttribute("id", id);
	}
		
	public Element getElement(String s) {
		
		return getDescendants(WidgetFactory.getIdFilter(s)).hasNext() ? 
				(Element)getDescendants(WidgetFactory.getIdFilter(s)).next() : null;
	}

	
	public String toString() {
        XMLOutputter output = new XMLOutputter(Format.getPrettyFormat().setOmitDeclaration(true));
        return output.outputString(this);
	}
	
	public String contentString() {
		return getDescendants().hasNext() ? ((Widget)getDescendants().next()).toString() : "";
	}
}
